using System.Collections.Generic;

namespace RecommendedProduct
{
	public class ProductStaticManager
	{
		private static ProductStaticManager instance;

		private List<Product> _ignoreProducts = new List<Product>();

		private Dictionary<TypeGame, List<Product>> _rememberProduct = new Dictionary<TypeGame, List<Product>>();

		public List<Product> IgnoreProducts
		{
			get
			{
				Product product = MarketController.Instance.GetProduct("Boost");
				if (!_ignoreProducts.Contains(product))
				{
					_ignoreProducts.Add(product);
				}
				return _ignoreProducts;
			}
		}

		private ProductStaticManager()
		{
		}

		public static ProductStaticManager GetInstance()
		{
			if (instance == null)
			{
				instance = new ProductStaticManager();
			}
			return instance;
		}

		public List<Product> GetProduct(TypeGame typeGame)
		{
			if (!_rememberProduct.ContainsKey(typeGame))
			{
				_rememberProduct.Add(typeGame, new ProductGameTypeConfig().GetProduct(typeGame));
			}
			return _rememberProduct[typeGame];
		}

		public void AddProductToIgnore(List<Product> products)
		{
			IgnoreProducts.AddRange(products);
		}

		public void ClearProductsByTypeGame(TypeGame typeGame)
		{
			if (!_rememberProduct.ContainsKey(typeGame))
			{
				return;
			}
			foreach (Product item in _rememberProduct[typeGame])
			{
				IgnoreProducts.Remove(item);
			}
			_rememberProduct.Remove(typeGame);
		}

		public void ClearProductByCategory(string category, string subCategory)
		{
			IgnoreProducts.RemoveAll((Product x) => x.categoryName == category && x.subCategoryName == subCategory);
		}

		public void ClearAll()
		{
			_rememberProduct.Clear();
			IgnoreProducts.Clear();
		}
	}
}
